package com.yunji.product.business;

import com.yunji.common.base.BaseBusiness;
import com.yunji.common.enums.common.ErrorEnum;
import com.yunji.product.domain.ProductTypeDO;
import com.yunji.product.params.ProductTypeParam;
import com.yunji.product.service.IProductService;
import com.yunji.product.service.IProductTypeService;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package com.yunji.product.business
 * @FileName ProductTypeBusiness.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * @Company com
 * @Version 1.0
 * @Since JDK1.8.0_201
 * @CreateTime 2024-06-10 23:37:33
 * @Description 产品类型
 * @Modification History
 * Author					History Time			Version			Description
 * -------------------------------------------------------------------------------
 * HuaAo0803@163.com	2024-06-10 23:37:33		1.0				1.0
 */
@Component
public class ProductTypeBusiness extends BaseBusiness {
    @Resource
    IProductService productService;

    @Resource
    IProductTypeService productTypeService;

    /**
     * @Title search
     * @Desc 查询商品类型列表
     * @Date 2024-06-12 10:41:23.794
     * @Return List<ProductType> 商品类型列表
     */
    public List<ProductTypeDO> search(ProductTypeParam param) {
        return productTypeService.search(param);
    }

    /**
     * @param id 商品类型ID
     * @Title select
     * @Desc 获取商品类型详情
     * @Date 2024-06-12 10:53:20.779
     * @Return ProductType 商品类型详情
     */
    public ProductTypeDO select(Long id) {
        return productTypeService.select(id);
    }

    /**
     * @param productType 商品类型信息
     * @Title create
     * @Desc 创建商品类型信息
     * @Date 2024-06-12 10:49:08.959
     */
    public Integer create(ProductTypeDO productType) {
        Assert.isTrue(productTypeService.create(productType), "新增失败");
        return productType.getId();
    }

    /**
     * @param productType 商品类型信息
     * @Title update
     * @Desc 更新商品类型信息
     * @Date 2024-06-12 10:49:36.909
     */
    public void update(ProductTypeDO productType) {
        Assert.isTrue(productTypeService.update(productType), "修改失败");
    }

    /**
     * @param ids 商品类型ID数组
     * @Title delete
     * @Desc 删除商品类型
     * @Date 2024-06-12 10:32:09.384
     */
    public void delete(Long... ids) {
        Assert.isTrue((productService.statsOfProductType(ids) == 0), ErrorEnum.BUSINESS_512001.getText());
        productTypeService.delete(ids);
    }

    public Boolean inUse(Long typeId) {
        return (productService.statsOfProductType(typeId) > 0) ? Boolean.TRUE : Boolean.FALSE;
    }
}